<?php
namespace app\common\model;

use think\Model;

class Rule extends Model
{
    protected $pk     = 'id';
    protected $table   = "fs_auth_rule";



    public function getRule($where)
    {
        return $this::where($where)->find();
    }

    public function getRules($where=[])
    {
        $rule = $this::where($where)->select();
         if ($rule) {
            $rule = collection($rule)->toArray();
        }
        return $rule;
    }

    public function saveRule($data, $where = false)
    {
        if ($where) {
            return $this::where($where)->update($data);
        } else {
            if ($this::save($data)) {
                return $this->id;
            }
        }
    }

    public function delRule($id)
    {
        if ($id) {
            $where['id'] = ["in", $id];
            return $this::where($where)->delete();
        }
    }
}
